#!/bin/bash
Temp=`hostname -s|grep lxslc6`
if [ "T$Temp" = "T" ]
then
        #echo Temp is not lxslc6

ps -eo pid,user,cputime,%cpu,command |egrep -v -w "(' root '|rpc|rpcuser|mysql|ntp|smmsp|xfs|daemon|gdm|postfix|ganga|' argorec '|' argod '|scp|paw|cc|gcc|f77|' niejy '|' swtest '|' offline '|' maggiora '|' mdestefa ')" |awk -F' ' {'if (($3>"02:00:00") && ($4+0>"60"+0)) {system("kill -9 " $1); system("/afs/ihep.ac.cn/u07/public/system/warn -u  " $2 " /afs/ihep.ac.cn/u07/public/system/warn_message"); system("date"); print $1 " " $2 " " $3 " " $4 " " $5}'} >>/var/log/kill_process.log
ps -eo pid,user,cputime,%mem,command |egrep -v -w "(' root '|rpc|rpcuser|mysql|ntp|smmsp|xfs|daemon|gdm|postfix|ganga|' argorec '|' argod '|scp|paw|cc|gcc|f77|' niejy '|' swtest '|' offline '|' maggiora '|' mdestefa ')" |awk -F' ' {'if ( ($4+0>"20"+0)) {system("echo " $1); system("/afs/ihep.ac.cn/u07/public/system/warn -u  " $2 " /afs/ihep.ac.cn/u07/public/system/warn_message"); system("date"); print $1 " " $2 " " $3 " " $4 " " $5}'} >>/var/log/kill_process.log

else  #if lxslc6

ps -eo pid,user,cputime,%cpu,command |egrep -v -w "(' root '|rpc|rpcuser|mysql|ntp|smmsp|xfs|daemon|gdm|postfix|salaman|stefanomaria|scp|paw|cc|gcc|f77|ganga|' niejy '|' swtest '|' offline '|' maggiora '|' mdestefa ')" |awk -F' ' {'if (($3>"02:00:00") && ($4>"60")) {system("kill -9 " $1); system("/afs/ihep.ac.cn/u07/public/system/warn -u  " $2 " /afs/ihep.ac.cn/u07/public/system/warn_message"); system("date"); print $1 " " $2 " " $3 " " $4 " " $5}'} >>/var/log/kill_process.log
ps -eo pid,user,cputime,%mem,command |egrep -v -w "(' root '|rpc|rpcuser|mysql|ntp|smmsp|xfs|daemon|gdm|postfix|salaman|stefanomaria|scp|paw|cc|gcc|f77|ganga|' niejy '|' swtest '|' offline '|' maggiora '|' mdestefa ')" |awk -F' ' {'if ( ($4>"20")) {system("echo " $1); system("/afs/ihep.ac.cn/u07/public/system/warn -u  " $2 " /afs/ihep.ac.cn/u07/public/system/warn_message"); system("date"); print $1 " " $2 " " $3 " " $4 " " $5}'} >>/var/log/kill_process.log

fi
